﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using ServiceInterfaces.Stores;
using DTO.Common;

namespace Teste3
{
    class Program
    {
        static void Main(string[] args)
        {

            ListProducts();
            SellProducts();
            CheckAvailability();

        }

        static void CheckAvailability()
        {
            Console.WriteLine("CheckAvailability");

            ChannelFactory<IStoreSales> factory = new ChannelFactory<IStoreSales>("store");
            IStoreSales store = factory.CreateChannel();

            List<Product> products = store.CheckAvailability(new List<SoldProduct> { 
                new SoldProduct{ Amount = 2, Product = new Product { Code = 67 } }
            });

            foreach (Product p in products) {
                Console.WriteLine(p.ToString());
                Console.WriteLine("-------------------------------------");
            }

            factory.Close();
        }

        static void SellProducts()
        {
            Console.WriteLine("SellProducts");

            ChannelFactory<IStoreSales> factory = new ChannelFactory<IStoreSales>("store");
            IStoreSales store = factory.CreateChannel();

            store.Sell(new List<SoldProduct> { 
                new SoldProduct{ Amount = 2, Product = new Product { Code = 67 } }
            });
            
            factory.Close();
        }

        static void ListProducts()
        {
            Console.WriteLine("ListProducts");

            ChannelFactory<IStoreSales> factory = new ChannelFactory<IStoreSales>("store");
            IStoreSales store = factory.CreateChannel();

            ProductList list = store.GetProducts(1, 10);
            Console.WriteLine("Total = {0}", list.Total);
            foreach (Product p in list.Products)
            {
                Console.WriteLine(p.ToString());
                Console.WriteLine("----------------------------");
            }

            factory.Close();
        }
    }
}
